/*
 * ComboBoxWizard3.java
 *
 * Created on May 22, 2006, 2:51 AM
 */


import java.util.Vector;
import javax.swing.AbstractButton;
import javax.swing.JOptionPane;

/**
 *
 * @author  yaco
 */
public class ComboBoxWizard3 extends javax.swing.JFrame {

    Vector<String> tables=new Vector<String>();
    static String table;
    /** Creates new form ComboBoxWizard4 */
    public ComboBoxWizard3() {
        initComponents();
        this.setSize(550,350);
        this.setLocation(250,200);
        tables=MainWindow.dbCon.getTables();
        final int size=tables.size();
        jList1.setModel(new javax.swing.AbstractListModel() {
                        String[] strings = new String[size];         
                        public int getSize() {   
                                for(int i=0;i<size;i++){
                                    strings[i]=tables.elementAt(i);
                                }
                                return strings.length;
                        }
                        
                        public Object getElementAt(int i) {
                                return strings[i]; 
                        }
        });
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        getContentPane().setLayout(null);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Combo Box Wizard");
        setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("mysql.JPEG")));
        setResizable(false);
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/db.png")));
        jLabel1.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        getContentPane().add(jLabel1);
        jLabel1.setBounds(10, 10, 120, 250);

        jLabel2.setText("Which table should provide the values for your combo box?");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(150, 20, 400, 14);

        jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jList1);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(150, 60, 300, 180);

        getContentPane().add(jLayeredPane1);
        jLayeredPane1.setBounds(0, 0, 0, 0);

        getContentPane().add(jSeparator1);
        jSeparator1.setBounds(0, 0, 0, 2);

        getContentPane().add(jSeparator2);
        jSeparator2.setBounds(10, 260, 520, 20);

        jButton1.setText("Cancel");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        getContentPane().add(jButton1);
        jButton1.setBounds(130, 280, 80, 23);

        jButton2.setText("<  Back");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        getContentPane().add(jButton2);
        jButton2.setBounds(260, 280, 90, 23);

        jButton3.setText("Next  >");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });

        getContentPane().add(jButton3);
        jButton3.setBounds(350, 280, 90, 23);

        jButton4.setText("Finish");
        jButton4.setEnabled(false);
        getContentPane().add(jButton4);
        jButton4.setBounds(440, 280, 90, 23);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
// TODO add your handling code here:
        this.dispose();
        ComboBoxWizard1.comboBoxWizard1.setVisible(true);
    }//GEN-LAST:event_jButton2MouseClicked

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
        this.dispose();
        ComboBoxWizard1.comboBoxWizard4=new ComboBoxWizard4();
        ComboBoxWizard1.comboBoxWizard4.setVisible(true); 
        table=(String)jList1.getSelectedValue();               
        ComboBoxWizard1.comboBoxWizard4.fields=MainWindow.dbCon.getFields(table);
        ComboBoxWizard1.comboBoxWizard4.size=ComboBoxWizard1.comboBoxWizard4.fields.size();
        ComboBoxWizard1.comboBoxWizard4.list1Data=ComboBoxWizard1.comboBoxWizard4.fields;
        ComboBoxWizard1.comboBoxWizard4.fields=MainWindow.dbCon.getFields(table);
        ComboBoxWizard1.comboBoxWizard4.jList1.setModel(new javax.swing.AbstractListModel() {
        String[] strings = new String[ComboBoxWizard1.comboBoxWizard4.size];
          
            public int getSize() {   
                    for(int i=0;i<ComboBoxWizard1.comboBoxWizard4.size;i++) {
                        strings[i]=(String) ComboBoxWizard1.comboBoxWizard4.fields.elementAt(i);
                    }
                    return strings.length;
            }
            
            public Object getElementAt(int i) {
                    return strings[i]; 
            }
        }); 
// TODO add your handling code here:

     
    }//GEN-LAST:event_jButton3MouseClicked

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        this.dispose();
// TODO add your handling code here:
    }//GEN-LAST:event_jButton1MouseClicked
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
             ComboBoxWizard1.comboBoxWizard4.setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLayeredPane jLayeredPane1;
    public javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    // End of variables declaration//GEN-END:variables
    
}
